/*仓库类型字段
 * @Author: your name
 * @Date: 2022-11-25 13:29:44
 * @LastEditTime: 2022-11-25 16:08:01
 * @LastEditors: DESKTOP-4QFD9PO
 * @Description: In User Settings Edit
 * @FilePath: \ClothMes\src\service\wh\index.ts
 */
import { post, get } from "@/api/http"
import { ref } from 'vue'

/**
 * @Interface 仓库类型字段
 */
export interface WhTypeField {

    "id": number | string | undefined,
    "serialNo": number,
    "conditionState": number,
    "mustState": number,
    "valueType": number,
    "showState": number,
    "fieldName": string,
    "requestField": string,
    "requestUrl": string,
    warehouseTypeName: string,
    warehouseTypeId: number | string
}
/**
 * @Interface 公司树形列表
 */
export interface CompanyList {
    value: number
    label: string
    disabled: boolean
    children: CompanyList[] | undefined
}

export interface firmList {
    firm: string,
    firmId: string,
}

/**
 * @Intface 仓库
 */
export interface Warhouse {



    id: number;

    /**
     * 工厂;公司
     */

    firm: String;
    /**
     * 仓库代号
     */

    warehouseCode: String;

    /**
     * 仓库名称
     */

    warehouseName: String;

    /**
     * 计件方式
     */

    pricingWay: String;


    /**
     * 备注;备注
     */

    remark: String;

    /**
     * 是否删除;0未删除 1已删除;是否删除 0未删除 1已删除
     */

    deleteState: number;

    /**
     * 创建人;创建人
     */

    createName: String;

    /**
     * 创建时间;创建时间
     */

    createTime: String;

    /**
     * 修改人;修改人
     */

    updateName: String;

    /**
     * 修改时间;修改时间
     */

    updateTime: String;

    /**
     * 是否作废 0默认  1作废;是否作废 0默认  1作废
     */

    obsoleteState: number;




    /**
     * 仓库类别id
     */

    warehouseTypeId: String;


    /**
     * 仓库类别名称
     */

    warehouseTypeName: String;

    /**
     * 库存表名
     */

    stockTableName: String;


}
/**
 * @Intface 仓库类型
 */
export interface WarhouseType {
    "id": number
    "typeCode": string
    "typeName": string
    "remark": string
}



/** 
 *@Description: 仓库service
 *@ClassAuthor: T.Y.Z
 *@Date: 2022-11-24 21:04:28
*/
class WHService {

    /**
     * @Description 仓库类型
     */
    whTypeList = ref<WarhouseType[]>([])

    /**
     * @Description 仓库类型字段数组
     */
    whTypeFieldList = ref<WhTypeField[]>([])
    /**
    * @Description 公司数组
    */
    companyList = ref<CompanyList[]>([])

    /**
    * @Description 仓库数组
    */
    whList = ref<Warhouse[]>([])


    constructor() {
        this.loadCompanyList()
        this.getWarhouseTypeList()
    }

    /**
     * @Function      获取公司部门树形
     * @Description: 
     * @MethodAuthor: T.Y.Z
     * @Date: 2022-11-25 15:21:05
    */
    getDepartmentList = () => {
        return get({
            url: 'hr/department/getAllActiveDepartment'
        })
    }

    /**
     * @description: 获取仓库类型字段List
     */
    loadWHTypeFieldList = (data:any): void => {
        const _this = this
        post({
            url: 'wms/warehouseBindField/getFieldByShowType',
            data: data
        }).then(({ code, data }) => {
            if (code === 200) {
                _this.whTypeFieldList.value = data as WhTypeField[]
            }
        })
    }


    /**
     * @description: 获取公司列表
     */
    loadCompanyList = (): void => {
        const _this = this
        // post({
        //     url: 'org/firmGroup/getFirmInfoByMap',
        // }).then(({ code, data }) => {
        //     if (code === 200) {
        //         _this.companyList.value = data
        //     }
        // })
    }

    /**
     * @description: 获取仓库列表
     * @param {string} firm
     * @param {string} whTypeName
     */
    getWarhouseList = (firm: string, whTypeName: string): void => {
        const _this = this
        post({
            url: 'wms/warehouse/getWarehouseByPara',
            data: {
                firmId: firm,
                warehouseTypeName: whTypeName,
                virtuallyState:0
            }
        }).then(({ code, data }) => {
            if (code === 200) {
                _this.whList.value = data
            }
        })
    };
    getWarhouseListByFirmId = (firmId:number,whTypeName: string): void => {
        const _this = this
        post({
            url: 'wms/warehouse/getWarehouseByPara',
            data: {
                firmId: firmId,
                warehouseTypeName: whTypeName,
                virtuallyState:0
            }
        }).then(({ code, data }) => {
            if (code === 200) {
                _this.whList.value = data
            }
        })
    }

    getWarhouseListByFirmId22 = (firmId:number): void => {
        const _this = this
        post({
            url: 'wms/warehouse/getWarehouseByPara',
            data: {
                firmId: firmId,
                virtuallyState:0
            }
        }).then(({ code, data }) => {
            if (code === 200) {
                _this.whList.value = data
            }
        })
    }

    /**
     * @description: 获取仓库类型列表
     */
    getWarhouseTypeList = () => {
        post({
            url: 'wms/warehouseType/getWarehoursTypePara',
            data: {}
        }).then(({ code, data }) => {
            if (code === 200) {
                this.whTypeList.value = data
            }
        })
    }

    /**
     * @description: 获取仓库明细列表
     */
    getWarhouseMinxList = async (orderNo: any, warehouseTypeName: any, warehouseName: any, firm: any) => {
        const res = await post({
            url: 'wms/WarehousetypeFieldvalue/getInvoicesByPara',
            data: {
                orderNo,
                warehouseTypeName,
                warehouseName,
                firmId:firm
            }
        })
        return res
    }


    /**
     * @description: 获取仓库明细列表
     */
    addWarhouseMinxList = async (addData: any) => {
        const res = await post({
            url: 'wms/WarehousetypeFieldvalue/insertInvoices',
            data: addData
        })
        return res
    }

    /**
     * @description: 修改仓库明细列表
     */
    updataWarhouseMinxList = async (addData: any) => {
        const res = await post({
            url: 'wms/WarehousetypeFieldvalue/updateInvoicesById',
            data: addData
        })
        return res
    }

    /**
     * @description: 删除仓库类型
     */
    deletWarhouseMinxList = async (addData: any) => {
        const res = await post({
            url: 'wms/WarehousetypeFieldvalue/delInvoicesByOrderNo',
            data: addData
        })
        return res
    }

    /**
     * @description: 删除仓库明细
     */
    deletWhmxWarhouseMinxList = async (addData: any) => {
        const res = await post({
            url: 'wms/WarehousetypeFieldvalue/delInvoicesById',
            data: addData
        })
        return res
    }

    /**
     * @description: 审核仓库单据
     */
    auditsWhmxWarhouse = async (auditsData: any) => {
        const res = await post({
            url: 'wms/WarehousetypeFieldvalue/updateByOrderNo',
            data: auditsData
        })
        return res
    }

    /**
     * @description: 获取单据打印
     */
    DyWhmxWarhouse = async (auditsData: any) => {
        const res = await post({
            url: 'wms/WarehousetypeFieldvalue/printInvoices',
            data: auditsData
        })
        return res
    }

    /**
     * @description: 获取扫描单据
     */
    smWhmxWarhouse = async (auditsData: any) => {
        const res = await post({
            url: 'wms/stock/scanInvoices',
            data: auditsData
        })
        return res
    }

    /**
     * @description: 获取扫描单据
     */
    smWhmxWarhouses = async (auditsData: any) => {
        const res = await post({
            url: 'wms/stock/scanVerify',
            data: auditsData
        })
        return res
    }
    
    /**
     * @description: 获取扫描单据
     */
    smWhmxWarhouses2 = async (auditsData: any) => {
        const res = await post({
            url: 'wms/stock/scanInvoicesBatch',
            data: auditsData
        })
        return res
    }

    /**
     * @description: 入库扫描确认
     */
    rkSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'wms/stock/affirmInStock',
            data: qrDatas
        })
        return res
    }

    /**
     * @description: 出库扫描确认
     */
    ckSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'wms/stock/affirmOutStock',
            data: qrDatas
        })
        return res
    }

    /**
         * @description: 转仓入库扫描确认
         */
    zcRkSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'wms/stock/affirmZcInStock',
            data: qrDatas
        })
        return res
    }

    /**
     * @description: 转仓出库扫描确认
     */
    zcCkSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'wms/stock/affirmZcOutStock',
            data: qrDatas
        })
        return res
    }

    /**
     * @description: 退货入库扫描确认
     */
     thrCkSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'wms/stock/affirmReturnInStock',
            data: qrDatas
        })
        return res
    }

    /**
     * @description: 退货出库扫描确认
     */
     thcCkSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'wms/stock/affirmReturnOutStock',
            data: qrDatas
        })
        return res
    }

    /**
     * @description: 流水查询下拉框数据
     */
    liusuiCkSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'wms/warehousetypeDrop/getDropDataByLs',
            data: qrDatas
        })
        return res
    }

     /**
     * @description: 查询采购单
     */
     cgCxSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'purchase/PurchaseOrder/getUseCompanybyFirm',
            data: qrDatas
        })
        return res
    }

    /**
     * @description: 查询采购单明细
     */
    cgCxMxSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'purchase/PurchaseOrder/getPurchaseCode',
            data: qrDatas
        })
        return res
    }

    /**
     * @description: 查询原料信息
     */
    wlCxMxSmWhmxWarhouse = async (qrDatas: any) => {
        const res = await post({
            url: 'product/Rawmaterial/getListByWarehouse',
            data: qrDatas
        })
        return res
    }


}

export default WHService